<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

use App\Models\User;

class UserController extends AdminController
{
    protected $title = '用户';

    protected function grid()
    {
        $grid = new Grid(new User);

        $grid->column('id', 'ID');
        $grid->column('name', '名称');
        $grid->column('avatar', '头像')->image('', 80, 80);
        $grid->column('points', '积分')->label('info');
        $grid->column('weapp_openid', '小程序-open_id');
        $grid->column('created_at', '添加时间');

        $grid->disableCreateButton();

        $grid->disableExport();

        $grid->disableActions();

        $grid->tools(function ($tools) {
            $tools->batch(function ($batch) {
                $batch->disableDelete();
            });
        });

        // $grid->actions(function ($actions) {
        //     $actions->disableDelete();

        //     $actions->disableEdit();

        //     $actions->disableView();
        // });

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('phone', __('Phone'));
        $show->field('email', __('Email'));
        $show->field('email_verified_at', __('Email verified at'));
        $show->field('password', __('Password'));
        $show->field('weixin_openid', __('Weixin openid'));
        $show->field('weapp_openid', __('Weapp openid'));
        $show->field('weixin_session_key', __('Weixin session key'));
        $show->field('weixin_unionid', __('Weixin unionid'));
        $show->field('remember_token', __('Remember token'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    protected function form()
    {
        $form = new Form(new User);

        $form->text('name', __('Name'));
        $form->mobile('phone', __('Phone'));
        $form->email('email', __('Email'));
        $form->datetime('email_verified_at', __('Email verified at'))->default(date('Y-m-d H:i:s'));
        $form->password('password', __('Password'));
        $form->text('weixin_openid', __('Weixin openid'));
        $form->text('weapp_openid', __('Weapp openid'));
        $form->text('weixin_session_key', __('Weixin session key'));
        $form->text('weixin_unionid', __('Weixin unionid'));
        $form->text('remember_token', __('Remember token'));

        return $form;
    }
}
